package com.foreveross.taskservice.web.controller.task;

import java.util.List;

import javax.annotation.Resource;

import org.dayatang.querychannel.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.foreveross.taskservice.application.pages.IPageChannelApplication;
import com.foreveross.taskservice.application.pages.IPageTaskCacheQueryApplication;
import com.foreveross.taskservice.application.pages.vos.BaseQueryVO;
import com.foreveross.taskservice.application.task.statsdetail.vo.BaseChannelVO;
import com.foreveross.taskservice.application.task.statsdetail.vo.BaseTaskVO;
import com.foreveross.taskservice.web.controller.auth.BaseController;
/**
 * 任务查询
 * @author guokenye
 *
 */
@Controller
@RequestMapping("/task/TaskQuery")
public class TaskQueryController extends BaseController{
	@Resource(name="pageChannelApplicationImpl")
	private IPageChannelApplication pageChannelApplication;
	@Resource(name="pageTaskCacheQueryApplicationImpl")
	private IPageTaskCacheQueryApplication pageTaskCacheQueryApplication;
	/**
	 * 进入查询页面jspPage
	 * @param modelMap
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/fetchQueryPage")
	public String fetchQueryPage(ModelMap modelMap)throws Exception{
		List<BaseChannelVO> vos=pageChannelApplication.getAllChannels();
		modelMap.put("channels", vos);
		return "task/taskQuery-queryPage";
	}
	
	/**
	 * 查询
	 * @param q
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/query")
	public Page<BaseTaskVO> query(BaseQueryVO q)throws Exception{
		Page<BaseTaskVO> page=pageTaskCacheQueryApplication.query(q);
		return page;
	}
	@ResponseBody
	@RequestMapping(params="method=queryByResultId")
	public Page<BaseTaskVO> query(String resultId,int offset,int count)throws Exception{
		Page<BaseTaskVO> page=pageTaskCacheQueryApplication.query(resultId, offset, count);
		return page;
	}
	
	@ResponseBody
	@RequestMapping(params="method=queryByTaskId")
	public BaseTaskVO query(String taskId)throws Exception{
		return pageTaskCacheQueryApplication.query(taskId);
	}
	
}
